﻿using Microsoft.Extensions.Logging;
using System.Collections.Concurrent;

namespace FunnyArts.PrettyClient.Core.Logger
{
    public class LoggerManager
    {
        private static ConcurrentDictionary<string, ILogger> loggers = new ConcurrentDictionary<string, ILogger>();

        public static ILogger Init(string logFilePath, string fileName)
        {
            var fullPath = Path.Combine(logFilePath, $"{fileName}-{DateTime.Now.ToString("yyyy-MM-dd")}.log");
            var loggerFactory = LoggerFactory.Create(builder =>
            {
                builder.AddProvider(new FileLoggerProvider(fullPath));
            });
            var logger = loggerFactory.CreateLogger(fullPath);
            loggers.AddOrUpdate(fullPath, logger, (s, l) => logger);
            return logger;
        }
    }
}
